import cv2

# 指定摄像头设备路径
device_path = '/dev/video21'

def cap_read():
    # 创建VideoCapture对象
    cap = cv2.VideoCapture(device_path)

    if not cap.isOpened():
        print(f"无法打开设备 {device_path}")
    else:
        print("成功打开摄像头")
    ret, frame = cap.read()

    if not ret:
        print("无法接收帧（可能是结束）")
    else:
        # 保存帧到当前路径
        cv2.imwrite('frame.jpg', frame)
        print("帧已保存为 frame.jpg")

    # 释放资源
    cap.release()
    cv2.destroyAllWindows()


#capread()
